<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\grid\GridView;
use yii\helpers\Url;
$this->title = '教师来源管理';
?>
<div class="container">
	<div class="row">
		<?php echo $this->render('_leftnav') ?>
		<div class="col-md-10">
			<div class="page-header clearfix">
				<h1 class="pull-left">教师来源管理</h1>
				<div class="pull-right">
					<a class="btn btn-success btn-sm" data-target="#addFrom" data-toggle="modal" >添加来源职位</a>
				</div>
			</div>
			<?php echo $this->render('_teachernav');?> 
			<table class="table table-hover" id="category-table">
				<thead>
					<tr>
						<th width="30%">名称</th>
						<th width="15%">排序</th>
						<th width="15%">是否显示</th>
						<th width="20%">添加时间</th>
						<th width="20%">操作</th>
					</tr>
				</thead>
				<tbody>
					<?php if($data){?>
					<?php foreach($data as $key => $val){?>
						<tr id="category-tr-3">
							<td><?= Html::encode($val['from_name']) ?></td>
							<td><?= Html::encode($val['from_sort']) ?></td>
							<td><?php 
									if($val['is_show']==1){
										echo "<font color='green'>显示</font>";
									}else{
										echo "<font color='red'>不显示</font>";
									}	
								?>
							</td>
							<td><?= date("Y-m-d H:s:i",Html::encode($val['from_addtime']))?></td>
							<td>
							<a href="javascript:;" class="btn btn-default btn-sm UpdateFrom" data-target="#UpdateFrom" data-toggle="modal" type="<?= Html::encode($val['from_id'])?>"><i class="glyphicon glyphicon-edit"></i> 编辑</a>
							<a href="javascript:;" class="btn btn-default btn-sm DeleteFrom" type="<?= Html::encode($val['from_id'])?>"><i class="glyphicon glyphicon-trash"></i> 删除</a>
							</td>
						</tr>
					<?php }}else{?>
						<tr>
							<td colspan="20">
								<div class="empty">暂无来源记录</div>
							</td>
						</tr>
					<?php }?>
				</tbody>
			</table>
		</div>
	</div>
</div>

<div id="addFrom" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">添加职位</h4>
			</div>
			<div class="modal-body">
				<div id="type-creater-widget">
					<?php 
						$form = ActiveForm::begin([
							'options' => ['class' => 'form-horizontal',
							'id'=>'type-form'],
							'action'=>Url::to(['user/fromcreate']),
							'method'=>'post',
							'fieldConfig' => [
								'template' => '<div class="form-group"><center><label class="col-md-2 control-label" for="type-name-field">{label}</label></center><div class="col-md-8 controls">{input}{error}</div></div>'
							], 
						]);
					?>
					<?= $form->field($model, 'from_name',['inputOptions'=>['placeholder'=>'请输入职位名称']])->textInput(['maxlength' => true]) ?>

					<?= $form->field($model, 'from_sort',['inputOptions'=>['value'=>50]])->textInput() ?>

					<?php $model->is_show=1; echo $form->field($model,'is_show')->radioList(['1'=>'显示','0'=>'不显示'],['separator'=>" ","style"=>"padding-top:6px;"]); ?> 
				</div>
			</div>
			<div class="modal-footer">	
				<button type="button" class="btn btn-link" data-dismiss="modal" tabindex="6">取消</button>
				<?= Html::submitButton('保存', ['class' => 'btn btn-success','id'=>'category-create-btn']) ?>
			</div>
			<?php ActiveForm::end(); ?>
		</div>
	</div>
</div>
<div id="UpdateFrom" class="modal fade"></div>
<script type="text/javascript">
	$(".DeleteFrom").click(function(){
		if(confirm("您确定要删除这条记录？")){
			var from_id=$(this).attr("type");
			$.ajax({
				type: "POST",
				url:"<?php echo Url::to(['user/fromdelete']);?>",
				data: "from_id="+from_id,
				dataType: 'json',
				success: function(msg){
					if (msg.code == 200) {
						history.go(0)
					}else if(msg.code == 400)
					{
						alert('删除失败')
					}else if(msg.code == 403) 
					{
						alert('暂无权限')
					}
				}
			});
		}
	})
	$(".UpdateFrom").click(function(){
		var from_id=$(this).attr("type");
		$.ajax({
			type: "POST",
			url: "<?php echo Url::to(['user/fromupdate']);?>",
			data: "from_id="+from_id+"&type=list",
			dataType: 'json',
			success: function(msg){
				if (msg.code == 200)
				{
					$("#UpdateFrom").html(msg.data);
				}else if(msg.code == 403)
				{
					$("#UpdateFrom").html('<div class="modal-dialog " style="width:170px;"><div class="modal-content"><div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h4 class="modal-title"><font color="red">'+msg.msg+'</font></h4></div></div></div>');
				}
			}
		});
	})
</script>